package it.univaq.mwt.frontoffice.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm extends ActionForm{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String password;
	private String username;
	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        
        this.username=null;
        this.password=null;
        
    }

        /**
         * Reset all properties to their default values.
         *
         * @param mapping The mapping used to select this instance
         * @param request The servlet request we are processing
       * @return errors
         */
      public ActionErrors validate( 
          ActionMapping mapping, HttpServletRequest request ) {
          ActionErrors errors = new ActionErrors();
          
          if( getUsername() == null || getUsername().length() < 1 ) {
            errors.add("username", new ActionMessage("error.username.required"));
          }
          if( getPassword() == null || getPassword().length() < 1 ) {
            errors.add("password", new ActionMessage("error.passoword.required"));
          }
          
          return errors;
      }
}
